package com.ityuwen.mengyagushi.payment.api;

import com.ityuwen.mengyagushi.common.login.GuiGuLogin;
import com.ityuwen.mengyagushi.common.result.Result;
import com.ityuwen.mengyagushi.payment.service.WxPayService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "微信支付接口")
@RestController
@RequestMapping("api/payment/wxPay")
@Slf4j
public class WxPayApiController {

    @Autowired
    private WxPayService wxPayService;

    @GuiGuLogin
    @PostMapping("createJsapi/{payType}/{orderNo}")
    public Result<Map<String, String>> createJsapi(@PathVariable("payType")String payType, @PathVariable("orderNo")String orderNo){
        Map<String, String> obj = this.wxPayService.createJsapi(payType, orderNo);
        return Result.ok(obj);
    }

    @PostMapping("pay/ok")
    @ResponseBody
    public Map<String, String> payOk(HttpServletRequest request){
        Map<String, String> map = this.wxPayService.payOk(request);
        return map;
    }

    @GetMapping("queryPayStatus/{orderNo}")
    public Result<Boolean> queryPayStatus(@PathVariable("orderNo")String orderNo){
        Boolean flag = this.wxPayService.queryPayStatus(orderNo);
        return Result.ok(flag);
    }
}
